#include "article.h"


Article::Article()
{
    unit = 0;
}

Article::Article(QString sendTime, QString id, int type)
{
    this->sendTime = sendTime;
    this->id = id;
    this->type = type;
}

void Article::packet(QString sender, QString receiver, QString info)
{
    this->sender = sender;
    this->receiver = receiver;
    this->info = info;
}

QString Article::sent()
{
    QString sendType;
    if (type == Article::NORMAL)    sendType = "普通";
    else if (type == Article::FRAG) sendType = "易碎品";
    else    sendType = "图书";
    //QSqlQuery query;
    QString str = QString("INSERT INTO expressinfo VALUES ('%1', '%2',"
                          "'%3', '%4', '%5', null, '等待揽收', null, %6)")
            .arg(id).arg(sendType).arg(sender).arg(sendTime).arg(receiver).arg(getPrice());
    return str;
}

void Article::received(QString recvTime)
{
    this->recvTime = recvTime;
    this->status = Article::RECV;
}

double Article::getPrice()
{
    return 15 * unit;
}

Fragile::Fragile(QString sendTime, QString id, double unit)
{
    type = Article::FRAG;
    this->sendTime = sendTime;
    this->id = id;
    this->unit = unit;
}

double Fragile::getPrice()
{
    return unit * 8;
}

Book::Book(QString sendTime, QString id, double unit)
{
    type = Article::BOOK;
    this->sendTime = sendTime;
    this->id = id;
    this->unit = unit;
}

double Book::getPrice()
{
    return unit * 2;
}

Normal::Normal(QString sendTime, QString id, double unit)
{
    type = Article::NORMAL;
    this->sendTime = sendTime;
    this->id = id;
    this->unit = unit;
}

double Normal::getPrice()
{
    return unit * 5;
}
